define(["jquery", "easy-admin"], function ($, ea) {
    var admintype = $("#admintype").val();
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'position/index',
        add_url: 'position/add',
        edit_url: 'position/edit',
        delete_url: 'position/delete',
        export_url: 'position/export',
        modify_url: 'position/modify',
    }; 
    var Controller = {
        index: function () {
            if(admintype == 1){
                ea.table.render({
                    init: init,
                    toolbar: ['refresh',
                        [
                            {
                                    text: '添加',
                                    url: init.add_url,
                                    method: 'open',
                                    auth: 'add',
                                    class: 'layui-btn layui-btn-normal layui-btn-sm',
                                    icon: 'fa fa-plus ',
                                    extend: 'data-full="true"',
                                }
                            ],
                        ],
                    cols: [[
                        {field: 'company_name', title: '公司名称'},
                        {field: 'position_name', title: '职位名称'},
                        {field: 'recruitment_area', title: '招聘区域', search: false},
                        // {field: 'pv', title: '浏览量', search: false},
                        // {field: 'uv', title: '浏览人数', search: false},
                       // {field: 'category_name', title: '所属分类'},
                        {field: 'expected_num', title: '最大报名人数', search: false},
                        {field: 'recruit_num', title: '报名人数', search: false},
                     
                        {field: 'cur_status', minWidth: 80, title: '岗位状态',selectList: {1: '已上架',2: '已下架',3: '待审核',4: '审核驳回'}},
                        {field: 'is_recommended', minWidth: 80, title: '推荐状态',selectList: {0: '否',1: '是'}},
                        {field: 'is_recommended', title: '是否推荐', templet:function(d) {
                            if(d.admintype == 1){
                                if (d.is_recommended == 0) {
                                    return '<a class="layui-btn layui-btn-sm"  data-request="position/recommended?id='+d.id+'" data-title="确定推荐吗？" data-table="currentTableRenderId">推荐</a>';
                                } else {
                                    return '已推荐';
                                }
                            }else{
                                return "";
                            }
                         
                        }},
                        {field: 'created_at', title: '发布时间', search: false},
                        {title: '操作', width:250,templet: function (d) {
                                return '<button class="layui-btn layui-btn-xs layui-btn-blue" data-open="registration_list/index?id='+d.id+'" data-full="true" data-title="报名列表">报名列表</button>' +
                                '<button class="layui-btn layui-btn-xs layui-btn-normal"  data-open="position/edit?id='+d.id+'" data-full="true" data-title="编辑" >编辑</button>'+
                                '<button class="layui-btn layui-btn-xs layui-btn-danger" data-request="position/delete?id='+d.id+'" data-title="确定删除？">删除</button>'
                                ;
                            }
                        }, 
    
                    ]],
                });    
            }else{
                ea.table.render({
                    init: init,
                    toolbar: ['refresh',
                        [
                            {
                                    text: '添加',
                                    url: init.add_url,
                                    method: 'open',
                                    auth: 'add',
                                    class: 'layui-btn layui-btn-normal layui-btn-sm',
                                    icon: 'fa fa-plus ',
                                    extend: 'data-full="true"',
                                }
                            ],
                        ],
                    cols: [[
                        {field: 'created_at',width:200, title: '发布时间', search: false,sort:true},
                        {field: 'company_name',width:100, title: '公司名称'},
                        {field: 'position_name', width:100,title: '职位名称'},
                        {field: 'recruitment_area',width:100, title: '招聘区域', search: false},
                        {field: 'pv', title: '浏览量',width:100, search: false},
                        {field: 'uv', title: '浏览人数', width:100, search: false},
                        {field: 'updated_at', title: '更新时间',width:200, search: false},
                        {field: 'recruit_num', title: '报名人数',width:100, search: false},
                        {field: 'cur_status', minWidth: 100, title: '岗位状态',selectList: {1: '已上架',2: '已下架',3: '待审核',4: '审核驳回'}},
                        {field: 'selection_date_start', title: '招聘开始日期',width:150, search: false},
                        {field: 'selection_date_end', title: '招聘结束日期',width:150, search: false},
                        {field: 'work_time_start', title: '招聘开始时间',width:150, search: false},
                        {field: 'work_time_end', title: '招聘结束时间', width:150,search: false},
                        {title: '操作', width:250,templet: function (d) {
                                return '<button class="layui-btn layui-btn-xs layui-btn-blue" data-open="registration_list/index?id='+d.id+'" data-full="true" data-title="报名列表">报名列表</button>' +
                                '<button class="layui-btn layui-btn-xs layui-btn-normal"  data-open="position/edit?id='+d.id+'" data-full="true" data-title="编辑" >编辑</button>'+
                                '<button class="layui-btn layui-btn-xs layui-btn-danger" data-request="position/delete?id='+d.id+'" data-title="确定删除？">删除</button>'
                                ;
                            }
                        }, 
    
                    ]],
                });
            };
          

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});